#pragma once


#include <QObject>
#include <QDataStream>
#include "AbstractProcedure.h"

#include "Network/Connection.h"
#include "Network/Manager.h"

#include "tccore_global.h"

namespace TC
{
    namespace Request
    {
        class TCCORE_EXPORT AbstractRemoteProcedure : public AbstractProcedure
        {
            Q_OBJECT
        using ConnectionType = decltype(Network::Manager::instance()->get("", QVariantMap()));
        public:
            AbstractRemoteProcedure(QObject *parent = nullptr);
            virtual ~AbstractRemoteProcedure();
        public:
            void get(const QString &command, const QVariantMap &args);
        public:
            Q_INVOKABLE void terminate();
        private:
            void onSocketReadyRead();
            void onSocketDisconnected();
        protected:
            virtual void onDataReady(QDataStream &stream) = 0;
        private:
            ConnectionType socket = nullptr;
        };
    }
}